<template>
  <div class="table-container">
    <el-table v-loading="listLoading" border :data="list" style="width: 100%" >
      <el-table-column :label="$t('table.name')" width="100px" fixed>
        <template slot-scope="scope">
          <span class="link-type" @click="handleUpdateCv(scope.row)">
          {{scope.row.candidate_name }}<i class="el-icon-edit"></i>
          </span>
        </template>
      </el-table-column>
      <el-table-column v-if='this.project_id ===""' label="项目名称" width="100px" fixed>
        <template slot-scope="scope">
          <span class="link-type" @click="handleViewProjectDesc(scope.row.project)">
            {{scope.row.project_name }}<svg-icon icon-class="share-square" />
          </span>
        </template>
      </el-table-column>
      <el-table-column label="项目公司" min-width="150px" fixed>
        <template slot-scope="scope">
          <span class="link-type" @click="handleViewCompanyDesc(scope.row.project)" v-if="scope.row.project && scope.row.project.company_name">
            {{ scope.row.project.company_name }}<svg-icon icon-class="share-square" />
          </span>
        </template>
      </el-table-column>
      <el-table-column label="客户经理" width="100px" >
        <template slot-scope="scope">
          <span v-if="scope.row.project && scope.row.project.client_manager">{{ getName(scope.row.project.client_manager) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="人才状态"  width="150px" >
        <template slot-scope="scope">
          <el-popover
            placement="bottom-start"
            width="600px"
            trigger="hover">
            <el-table :data="scope.row.op_history_group" :show-header="isDisplay" >
              <el-table-column width="200px">
                <template slot-scope="scope">
                  <i class="el-icon-time"></i>
                  <span style="margin-left: 10px">{{ scope.row.date | timeFilter('{y}-{m}-{d} {h}:{i}:{s}')}}</span>
                </template>
              </el-table-column>
              <el-table-column width="400px" >
                <template slot-scope="sub_scope">
                  <div><el-tag>
                    <span v-if="sub_scope.row.interview_date">
                      <span>{{ sub_scope.row.cv_status | cvStatusValFilter }}</span>
                      <span v-if="sub_scope.row.cv_status === 'interview' && sub_scope.row.interview_num" >: 第{{ sub_scope.row.interview_num}}轮</span>
                      <span> at {{ sub_scope.row.interview_date | timeFilter('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                    </span>
                    <span v-else-if="sub_scope.row.sign_date">{{ sub_scope.row.cv_status | cvStatusValFilter }} at {{ sub_scope.row.sign_date | timeFilter('{y}-{m}-{d}') }} </span>
                    <span v-else-if="sub_scope.row.board_date">{{ sub_scope.row.cv_status | cvStatusValFilter }} at {{ sub_scope.row.board_date | timeFilter('{y}-{m}-{d}') }} </span>
                    <span v-else>{{ sub_scope.row.cv_status | cvStatusValFilter }}</span>
                  </el-tag>
                  </div>
                  <div v-if="sub_scope.row.feedback">反馈:{{ sub_scope.row.feedback }}</div>
                  <div>操作者:{{ sub_scope.row.creator }}</div>
                </template>
              </el-table-column>
            </el-table>
            <el-tag slot="reference">
              <span>{{ scope.row.cv_status | cvStatusValFilter}}</span>
              <span v-if="scope.row.cv_status === 'interview'" >:第{{scope.row.interview_num}}轮</span>
            </el-tag>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="年薪"  width="100px" >
        <template slot-scope="scope">
          <span>{{scope.row.annual_salary }}</span>
        </template>
      </el-table-column>
      <el-table-column label="年龄"  width="100px" >
        <template slot-scope="scope">
          <span>{{ scope.row.birthday_date | timeFilter('{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机"  width="120px" >
        <template slot-scope="scope">
          <span>{{ scope.row.mobile_phone }}</span>
        </template>
      </el-table-column>
       <el-table-column label="操作时间"  width="100px" >
        <template slot-scope="scope">
          <span>{{scope.row.cv_op_time | timeFilter('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" align="center" :label="$t('table.actions')"  class-name="small-padding fixed-width" width="80px">
        <template slot-scope="scope">
          <el-dropdown @command="handleCommand" trigger="click">
              <span class="el-dropdown-link">
                <svg-icon icon-class="code" />
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item  :command='{type:"sent_to_manager", data: scope.row}' v-if="checkOperable(scope.row.cv_status, 'sent_to_manager') && (selfOperable(scope.row) || hasRoles(['SUPER_ADMIN']))" >推荐给客户经理</el-dropdown-item>
                <el-dropdown-item  :command='{type:"sent_to_client", data: scope.row}' v-if="checkOperable(scope.row.cv_status, 'sent_to_client') && (clientManagerOperable(scope.row) || hasRoles(['SUPER_ADMIN']))">推荐给客户</el-dropdown-item>
                <el-dropdown-item  :command='{type:"interview", data: scope.row}' v-if="checkOperable(scope.row.cv_status, 'interview') && (selfOperable(scope.row) || hasRoles(['SUPER_ADMIN']))" >面试</el-dropdown-item>
                <el-dropdown-item  :command='{type:"interview_end", data: scope.row}' v-if="checkOperable(scope.row.cv_status, 'interview_end') && (selfOperable(scope.row) || hasRoles(['SUPER_ADMIN']))" >终面</el-dropdown-item>
                <el-dropdown-item  :command='{type:"sign_offer", data: scope.row}' v-if="checkOperable(scope.row.cv_status, 'sign_offer') && (selfOperable(scope.row) || hasRoles(['SUPER_ADMIN']))" >签订Offer</el-dropdown-item>
                <el-dropdown-item  :command='{type:"onboading", data: scope.row}' v-if="checkOperable(scope.row.cv_status, 'onboading') && (selfOperable(scope.row) || hasRoles(['SUPER_ADMIN']))" >入职</el-dropdown-item>
                <el-dropdown-item  :command='{type:"over", data: scope.row}' v-if="checkOperable(scope.row.cv_status, 'sent_over') && (selfOperable(scope.row) || hasRoles(['SUPER_ADMIN']))" >过保证期</el-dropdown-item>
                <el-dropdown-item  :command='{type:"out", data: scope.row}' divided v-if="checkOperable(scope.row.cv_status, 'out') && (selfOperable(scope.row) || hasRoles(['SUPER_ADMIN']))" >淘汰</el-dropdown-item>
              </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="current_page" :page-sizes="[10,20,30, 50]"
        :page-size="listQuery.limit" layout="total, sizes, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
    <el-dialog title="安排面试" :visible.sync="dialogInterviewVisible" append-to-body>
      <el-form  :rules="interview_rules" ref="interviewForm" :model="interview_temp" label-position="left" label-width="70px" style='width: 400px; margin-left:50px;'>
        <el-form-item label="候选人" prop="name">
          <span> {{interview_temp.candidate_name}}</span>
        </el-form-item>
        <el-form-item label="面试时间" prop="interview_date">
          <el-date-picker v-model="interview_temp.interview_date" type="datetime" placeholder="选择时间" value-format="timestamp" >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" :rows="4" size="small" v-model="interview_temp.remark" style="width: 480px;"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogInterviewVisible = false">{{$t('table.cancel')}}</el-button>
        <el-button type="primary" @click="saveInterview()">{{$t('table.confirm')}}</el-button>
      </div>
    </el-dialog>

    <el-dialog title="终面" :visible.sync="dialogInterviewEndVisible" append-to-body>
      <el-form  :rules="interview_end_rules" :model="interview_end_temp" label-position="left" label-width="70px" style='width: 400px; margin-left:50px;'>
        <el-form-item label="候选人" prop="name">
          <span> {{interview_end_temp.candidate_name}}</span>
        </el-form-item>
        <el-form-item label="面试时间" prop="interview_date">
          <el-date-picker v-model="interview_end_temp.interview_date" type="datetime" placeholder="选择时间" value-format="timestamp" >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" :rows="4" size="small" v-model="interview_end_temp.remark" style="width: 480px;"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogInterviewEndVisible = false">{{$t('table.cancel')}}</el-button>
        <el-button type="primary" @click="saveInterviewEnd()">{{$t('table.confirm')}}</el-button>
      </div>
    </el-dialog>

    <el-dialog title="面试反馈" :visible.sync="dialogFeedbackVisible" append-to-body>
      <el-form  :rules="rules" ref="feedbackForm" :model="interview_temp" label-position="left" label-width="70px" style='width: 400px; margin-left:50px;'>
        <el-form-item label="候选人" prop="name">
          <span> {{this.current_cv.candidate_name}}</span>
        </el-form-item>
        <el-form-item label="面试" prop="name">
          <el-tag>
            {{ this.current_cv.cv_status | cvStatusValFilter }}
            <span v-if="this.current_cv.cv_status === 'interview' && this.current_cv.interview_num" >: 第{{ this.current_cv.interview_num }}轮</span>
          </el-tag>
        </el-form-item>
        <el-form-item label="反馈" prop="remark">
          <el-input type="textarea" :rows="4" size="small" v-model="interview_temp.feedback" style="width: 480px;"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFeedbackVisible = false">{{$t('table.cancel')}}</el-button>
        <el-button type="primary" @click="saveFeedback()">{{$t('table.confirm')}}</el-button>
      </div>
    </el-dialog>

    <el-dialog title="签订Offer" :visible.sync="dialogSignOfferVisible" append-to-body>
      <el-form  :rules="rules" ref="offerForm" :model="offer_temp" label-position="left" label-width="70px" style='width: 400px; margin-left:50px;'>
        <el-form-item label="候选人" prop="name">
          <span> {{offer_temp.candidate_name}}</span>
        </el-form-item>
        <el-form-item label="年薪" prop="annual_salary">
          <el-input size="small" v-model="offer_temp.annual_salary" style="width: 480px;"></el-input>
        </el-form-item>
        <el-form-item label="公司收费" prop="company_fees">
          <el-input size="small" v-model="offer_temp.company_fees" style="width: 480px;"></el-input>
        </el-form-item>
        <el-form-item label="签订时间" prop="company_fees">
          <el-date-picker
                v-model="offer_temp.sign_date"
                type="date"
                format="yyyy-MM-dd" value-format="timestamp"
                style="width: 200px;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="到岗时间" prop="remark">
          <el-date-picker
                v-model="offer_temp.board_date"
                type="date"
                format="yyyy-MM-dd" value-format="timestamp"
                style="width: 200px;">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogSignOfferVisible = false">{{$t('table.cancel')}}</el-button>
        <el-button type="primary" @click="saveOffer()">{{$t('table.confirm')}}</el-button>
      </div>
    </el-dialog>

    <el-dialog title="入职" :visible.sync="dialogBoadVisible" append-to-body>
      <el-form  :rules="rules" ref="boadForm" :model="boad_temp" label-position="left" label-width="70px" style='width: 400px; margin-left:50px;'>
        <el-form-item label="候选人" prop="name">
          <span> {{boad_temp.candidate_name}}</span>
        </el-form-item>
        <el-form-item label="到岗时间" prop="remark">
          <el-date-picker
                v-model="boad_temp.board_date"
                type="date"
                format="yyyy-MM-dd" value-format="timestamp"
                style="width: 200px;">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogBoadVisible = false">{{$t('table.cancel')}}</el-button>
        <el-button type="primary" @click="saveBoad()">{{$t('table.confirm')}}</el-button>
      </div>
    </el-dialog>

    <el-dialog title="淘汰" :visible.sync="dialogOutVisible" append-to-body>
      <el-form  :rules="rules" ref="outForm" :model="out_temp" label-position="left" label-width="70px" style='width: 400px; margin-left:50px;'>
        <el-form-item label="候选人" prop="name">
          <span> {{out_temp.candidate_name}}</span>
        </el-form-item>
        <el-form-item label="反馈" prop="remark">
          <el-input type="textarea" :rows="4" size="small" v-model="out_temp.feedback" style="width: 280px;"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogOutVisible = false">{{$t('table.cancel')}}</el-button>
        <el-button type="primary" @click="saveOut()">{{$t('table.confirm')}}</el-button>
      </div>
    </el-dialog>
    <CandidateReport :id="report_dialog.id" :visible="report_dialog.visible" @closeDialog="handleCloseReport">
    </CandidateReport>
  </div>
</template>

<script>
import API from '@/utils/backend_api'
import Static_Data from '@/data/index'
import CandidateReport from '@/views/candidate/components/candidateReport'

export default {
  name: 'cvTabPane',
  props: {
    cv_status: {
      type: String,
      default: ''
    },
    project_id: {
      type: String,
      default: ''
    },
    candidate_id: {
      type: String,
      default: ''
    }
  },
  components: { CandidateReport },
  data() {
    return {
      current_user_id: this.$store.getters.userId,
      current_user_roles: this.$store.getters.roles,
      total: 0,
      current_page: 1,
      list: null,
      listQuery: {
        page: 1,
        offset: 0,
        limit: 20,
        sort: '-create_date',
        cv_status: this.cv_status,
        project_id: this.project_id,
        candidate_id: this.candidate_id
      },
      listLoading: false,
      statusOptions: Static_Data.cv_status,
      userOptions: this.$store.getters.usersList,
      report_dialog: {
        id: '',
        visible: false
      },
      isDisplay: false,
      dialogInterviewVisible: false,
      dialogInterviewEndVisible: false,
      dialogFeedbackVisible: false,
      dialogSignOfferVisible: false,
      dialogBoadVisible: false,
      dialogOutVisible: false,
      action: '',
      tableKey: 0,
      rules: {
      },
      interview_rules: {
      },
      interview_end_rules: {
      },
      current_cv: {},
      interview_temp: {
        candidate_name: '',
        interview_date: '',
        feedback: '',
        remark: ''
      },
      interview_end_temp: {
        candidate_name: '',
        interview_date: '',
        feedback: '',
        remark: ''
      },
      offer_temp: {
        candidate_name: '',
        annual_salary: '',
        board_date: '',
        sign_date: '',
        company_fees: ''
      },
      boad_temp: {
        candidate_name: '',
        board_date: ''
      },
      out_temp: {
        candidate_name: '',
        feedback: ''
      }
    }
  },
  filters: {
  },
  created() {
    this.getList()
  },
  watch: {
    project_id: function(val, oldVal) {
      console.log('当前值为：' + val, '旧值为：' + oldVal)
      if (this.project_id && this.project_id !== '') {
        this.listQuery.project_id = this.project_id
        this.listQuery.cv_status = this.cv_status
        this.getList()
      }
    },
    candidate_id: function(val, oldVal) {
      console.log('当前值为：' + val, '旧值为：' + oldVal)
      if (this.candidate_id && this.candidate_id !== '') {
        this.listQuery.candidate_id = this.candidate_id
        this.listQuery.cv_status = this.cv_status
        this.getList()
      }
    }
  },
  methods: {
    selfOperable(data) {
      return data.create_id && this.current_user_id === data.create_id
    },
    clientManagerOperable(data) {
      return data.business_roles && data.business_roles.some((item) => (item === 'client_manager'))
      // return ((data.bd && this.current_user_id === data.bd.id) || (data.create_id && this.current_user_id === data.create_id))
    },
    hasRoles(roles) {
      return this.current_user_roles.some(item => roles.indexOf(item) >= 0)
    },
    handleViewProjectDesc(data) {
      if (data && data.id && data.project_name) {
        this.$router.push({
          name: 'projectDetail',
          params: {
            id: data.id,
            name: data.project_name,
            tab: 'base'
          }
        })
      }
    },
    handleViewCompanyDesc(data) {
      /* 验证是否存在查看权限 */
      if (data && data.company_id && data.company_name) {
        this.$router.push({
          name: 'companyDetail',
          params: {
            id: data.company_id,
            name: data.company_name,
            tab: 'base'
          }
        })
      }
    },
    getList() {
      this.listLoading = true
      if (this.cv_status === 'all') {
        this.listQuery.cv_status = ''
      }
      if ((this.listQuery.candidate_id && this.listQuery.candidate_id !== '') ||
        (this.listQuery.project_id && this.listQuery.project_id !== '')) {
        API.cv.all(this.listQuery).then(response => {
          this.list = response.data
          if (response.headers && response.headers['x-total-count']) {
            this.total = Number(response.headers['x-total-count'])
          }
          this.listLoading = false
        })
      }
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      if (val >= 1) {
        this.current_page = val
        this.listQuery.offset = (val - 1) * this.listQuery.limit
        this.getList()
      }
    },
    checkOperable(status, next_status) {
      if (status && next_status) {
        let next_status_group = []
        this.statusOptions.map(item => {
          if (item.key === status) {
            next_status_group = item.next_status_group
          }
        })
        if (next_status_group.indexOf(next_status) < 0) {
          return false
        } else {
          return true
        }
      } else {
        return false
      }
    },
    getName: function(id) {
      let username = ''
      this.userOptions.map(item => {
        if (item.id === id) {
          username = item.username
          return username
        }
      })
      return username
    },
    resetTemp() {
      this.interview_temp = {
        candidate_name: '',
        interview_date: '',
        feedback: '',
        remark: ''
      }
      this.interview_end_temp = {
        candidate_name: '',
        interview_date: '',
        feedback: '',
        remark: ''
      }
      this.offer_temp = {
        candidate_name: '',
        annual_salary: '',
        board_date: '',
        sign_date: '',
        company_fees: ''
      }
      this.boad_temp = {
        candidate_name: '',
        board_date: ''
      }
      this.out_temp = {
        candidate_name: '',
        feedback: ''
      }
    },
    handleUpdateCv(data) {
      if (data && data.id) {
        this.report_dialog = {
          id: data.id,
          visible: true
        }
      }
    },
    handleCloseReport() {
      this.report_dialog = {
        id: '',
        visible: false
      }
    },
    handleInterview(data) {
      this.interview_temp.candidate_name = data.candidate_name
      this.current_cv = data
      API.cv.getOpIshandle(this.current_cv.id).then(response => {
        console.log(response.data)
        if (response.data) {
          this.dialogInterviewVisible = true
        } else {
          this.dialogFeedbackVisible = true
        }
      })
    },
    handleInterviewEnd(data) {
      this.interview_end_temp.candidate_name = data.candidate_name
      this.current_cv = data
      API.cv.getOpIshandle(this.current_cv.id).then(response => {
        console.log(response.data)
        if (response.data) {
          this.dialogInterviewEndVisible = true
        } else {
          this.dialogFeedbackVisible = true
        }
      })
    },
    saveInterviewEnd() {
      API.cv.interview_end(this.current_cv.id, this.interview_end_temp).then(response => {
        for (const v of this.list) {
          if (v.id === this.current_cv.id) {
            const index = this.list.indexOf(v)
            this.list.splice(index, 1, response.data)
            break
          }
        }
        this.resetTemp()
        this.dialogInterviewEndVisible = false
      })
    },
    saveFeedback() {
      API.cv.feedback(this.current_cv.id, this.interview_temp).then(response => {
        for (const v of this.list) {
          if (v.id === this.current_cv.id) {
            const index = this.list.indexOf(v)
            this.list.splice(index, 1, response.data)
            break
          }
        }
        if (this.action === 'interview') {
          this.dialogInterviewVisible = true
        }
        if (this.action === 'interview_end') {
          this.dialogInterviewEndVisible = true
        }
        if (this.action === 'sign_offer') {
          this.dialogSignOfferVisible = true
        }
        if (this.action === 'out') {
          this.dialogOutVisible = true
        }
        this.dialogFeedbackVisible = false
      })
    },
    saveInterview() {
      API.cv.interview(this.current_cv.id, this.interview_temp).then(response => {
        for (const v of this.list) {
          if (v.id === this.current_cv.id) {
            const index = this.list.indexOf(v)
            this.list.splice(index, 1, response.data)
            break
          }
        }
        this.resetTemp()
        this.dialogInterviewVisible = false
      })
    },
    handleOffer(data) {
      this.offer_temp.candidate_name = data.candidate_name
      this.current_cv = data
      API.cv.getOpIshandle(this.current_cv.id).then(response => {
        console.log(response.data)
        if (response.data) {
          this.dialogSignOfferVisible = true
        } else {
          this.dialogFeedbackVisible = true
        }
      })
    },
    saveOffer() {
      API.cv.signoffer(this.current_cv.id, this.offer_temp).then(response => {
        for (const v of this.list) {
          if (v.id === this.current_cv.id) {
            const index = this.list.indexOf(v)
            this.list.splice(index, 1, response.data)
            break
          }
        }
        this.resetTemp()
        this.dialogSignOfferVisible = false
      })
    },
    handleBoad(data) {
      this.boad_temp.candidate_name = data.candidate_name
      this.current_cv = data
      API.cv.getOffer(data.id).then(response => {
        if (response.data && response.data.board_date) {
          this.boad_temp.board_date = response.data.board_date
        }
        this.dialogBoadVisible = true
      })
    },
    saveBoad() {
      API.cv.onboading(this.current_cv.id, this.boad_temp).then(response => {
        for (const v of this.list) {
          if (v.id === this.current_cv.id) {
            const index = this.list.indexOf(v)
            this.list.splice(index, 1, response.data)
            break
          }
        }
        this.resetTemp()
        this.dialogBoadVisible = false
      })
    },
    handleSentOver(data) {
      this.current_cv_status = data.cv_status
      this.current_cv = data
      this.$confirm(data.candidate_name + '已过保证期', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        API.cv.over(this.current_cv.id).then(response => {
          for (const v of this.list) {
            if (v.id === this.current_cv.id) {
              const index = this.list.indexOf(v)
              this.list.splice(index, 1, response.data)
              break
            }
          }
          this.$message({
            type: 'success',
            message: '成功!'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    handleOut(data) {
      this.out_temp.candidate_name = data.candidate_name
      this.current_cv = data
      API.cv.getOpIshandle(this.current_cv.id).then(response => {
        console.log(response.data)
        if (response.data) {
          this.dialogOutVisible = true
        } else {
          this.dialogFeedbackVisible = true
        }
      })
    },
    saveOut() {
      API.cv.out(this.current_cv.id, this.out_temp).then(response => {
        for (const v of this.list) {
          if (v.id === this.current_cv.id) {
            const index = this.list.indexOf(v)
            this.list.splice(index, 1, response.data)
            break
          }
        }
        this.resetTemp()
        this.dialogOutVisible = false
      })
    },
    sentToManager(data) {
      this.current_cv = data
      API.cv.send_client_manager(this.current_cv.id).then(response => {
        for (const v of this.list) {
          if (v.id === this.current_cv.id) {
            const index = this.list.indexOf(v)
            this.list.splice(index, 1, response.data)
            break
          }
        }
        this.resetTemp()
        this.$notify({
          title: '成功',
          message: '推荐成功',
          type: 'success',
          duration: 2000
        })
      })
    },
    sentToClient(data) {
      this.current_cv = data
      API.cv.send_client(this.current_cv.id).then(response => {
        for (const v of this.list) {
          if (v.id === this.current_cv.id) {
            const index = this.list.indexOf(v)
            this.list.splice(index, 1, response.data)
            break
          }
        }
        this.resetTemp()
        this.$notify({
          title: '成功',
          message: '推荐成功',
          type: 'success',
          duration: 2000
        })
      })
    },
    handleCommand(val) {
      if (val.type && val.data && val.type === 'sent_to_manager') {
        this.action = 'sent_to_manager'
        this.sentToManager(val.data)
      }
      if (val.type && val.data && val.type === 'sent_to_client') {
        this.action = 'sent_to_client'
        this.sentToClient(val.data)
      }
      if (val.type && val.data && val.type === 'interview') {
        this.action = 'interview'
        this.handleInterview(val.data)
      }
      if (val.type && val.data && val.type === 'interview_end') {
        this.action = 'interview_end'
        this.handleInterviewEnd(val.data)
      }
      if (val.type && val.data && val.type === 'sign_offer') {
        this.action = 'sign_offer'
        this.handleOffer(val.data)
      }
      if (val.type && val.data && val.type === 'onboading') {
        this.action = 'onboading'
        this.handleBoad(val.data)
      }
      if (val.type && val.data && val.type === 'over') {
        this.action = 'over'
        this.handleSentOver(val.data)
      }
      if (val.type && val.data && val.type === 'out') {
        this.action = 'out'
        this.handleOut(val.data)
      }
    },
    refreshData() {
      this.listQuery = {
        page: 1,
        offset: 0,
        limit: 20,
        sort: '',
        candidate_id: this.id,
        project_id: '',
        cv_status: ''
      }
      this.getList()
    }
  }
}
</script>

